﻿/*
 * tester: Pengfei Li
 */

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AircraftBattleServer;

namespace ServerInterfaceTestProject
{
    /// <summary>
    /// Summary description for IGameEngineServiceTest1
    /// </summary>
    public partial class IGameEngineServiceTest
    {

        /// <summary>
        ///several tests for AddAircraft
        ///</summary>
        [TestMethod()]
        public void AddAircraftTestA()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            MyPoint expected = new MyPoint(400, 400); // default value
            int id = 2; // TODO: Initialize to an appropriate value
            MyPoint p = null; // TODO: Initialize to an appropriate value
            double angle = 0; // TODO: Initialize to an appropriate value
            target.AddAircraft(id, p, angle);
            MyPoint actural = server.GetPosition(id);
            server.RemoveAircraft(2);
            Assert.AreEqual(expected.x, actural.x);
            Assert.AreEqual(expected.y, actural.y);
        }


        [TestMethod()]
        public void AddAircraftTestB1()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            bool expect = false;
            bool actural = true;
            try
            {
                int id = -1; // TODO: Initialize to an appropriate value
                MyPoint p = new MyPoint(200, 200); // TODO: Initialize to an appropriate value
                double angle = 30; // TODO: Initialize to an appropriate value
                target.AddAircraft(id, p, angle);
                MyPoint position = server.GetPosition(id);
                Console.Write(position.x + " " + position.y);
                server.RemoveAircraft(-1);
            }
            catch (Exception e)
            {
                if (e.Message == "Id can't be negative")
                    actural = false;
                else
                    Assert.Fail();
            }

            Assert.AreEqual(expect, actural);
        }


        [TestMethod()]
        public void AddAircraftTestB3()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            bool expect = false;
            bool actural = true;
            try
            {
                int id = 0; // TODO: Initialize to an appropriate value
                MyPoint p = new MyPoint(200, 200); // TODO: Initialize to an appropriate value
                double angle = 30; // TODO: Initialize to an appropriate value
                target.AddAircraft(id, p, angle);
                MyPoint position = server.GetPosition(id);
                Console.Write(position.x + " " + position.y);
                server.RemoveAircraft(0);
            }
            catch (Exception e)
            {
                if (e.Message == "Id can't be zero")
                    actural = false;
                else
                    Assert.Fail();
            }

            Assert.AreEqual(expect,actural);
        }

        [TestMethod()]
        public void AddAircraftTestB2()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            MyPoint expected = new MyPoint(200, 200);
            int id = 2;// TODO: Initialize to an appropriate value
            MyPoint p = new MyPoint(200, 200); // TODO: Initialize to an appropriate value
            double angle = -90; // TODO: Initialize to an appropriate value
            target.AddAircraft(id, p, angle);
            MyPoint actural = server.GetPosition(id);
            server.RemoveAircraft(2);
            Assert.AreEqual(expected.x, actural.x);
            Assert.AreEqual(expected.y, actural.y);
        }


        [TestMethod()]
        public void AddAircraftTestC()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            bool expected = false;
            bool actural = true;
            try
            {
                int id = 1000;// TODO: Initialize to an appropriate value
                MyPoint p = new MyPoint(300, 300); // TODO: Initialize to an appropriate value
                double angle = 90; // TODO: Initialize to an appropriate value
                target.AddAircraft(id, p, angle);
                server.RemoveAircraft(1000);
            }
            catch (Exception e)
            {
                if (e.Message == "Id not exsit")
                    actural = false;
            }

            Assert.AreEqual(expected, actural);

        }


        [TestMethod()]
        public void AddAircraftTestD()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            int id = 2;// TODO: Initialize to an appropriate value
            MyPoint p = new MyPoint(1000, 1000); // TODO: Initialize to an appropriate value
            MyPoint expected = new MyPoint(800, 600);
            double angle = 90; // TODO: Initialize to an appropriate value
            target.AddAircraft(id, p, angle);
            MyPoint actural = server.GetPosition(id);
            server.RemoveAircraft(2);
            Assert.AreEqual(expected.x, actural.x);
            Assert.AreEqual(expected.y, actural.y);

            p = new MyPoint(-200, -200);
            expected = new MyPoint(0, 0);
            target.AddAircraft(id, p, angle);
            actural = server.GetPosition(id);
            server.RemoveAircraft(2);
            Assert.AreEqual(expected.x, actural.x);
            Assert.AreEqual(expected.y, actural.y);

            p = new MyPoint(-200, 500);
            expected = new MyPoint(0, 500);
            target.AddAircraft(id, p, angle);
            actural = server.GetPosition(id);
            server.RemoveAircraft(2);
            Assert.AreEqual(expected.x, actural.x);
            Assert.AreEqual(expected.y, actural.y);
           
            p = new MyPoint(200, -200);
            expected = new MyPoint(200, 0);
            target.AddAircraft(id, p, angle);
            actural = server.GetPosition(id);
            server.RemoveAircraft(2);
            Assert.AreEqual(expected.x, actural.x);
            Assert.AreEqual(expected.y, actural.y);
        }


        /// <summary>
        ///several tests for RemoveAircraft
        ///</summary>
        [TestMethod()]
        public void RemoveAircraftTestA()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            bool expected = false;
            bool actural = true;
            int id = 2000; // TODO: Initialize to an appropriate value
            try
            {
                target.RemoveAircraft(id);
            }
            catch (Exception e)
            {
                if (e.Message == "Id does not exist.")
                    actural = false;
                else
                    Assert.Fail();
            }

            Assert.AreEqual(expected, actural);

        }


        [TestMethod()]
        public void RemoveAircraftTestB()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            bool expected = false;
            bool actural = true;
            int id = 0; // TODO: Initialize to an appropriate value
            try
            {
                target.RemoveAircraft(id);
            }
            catch (Exception e)
            {
                if (e.Message == "Id does not exist.")
                    actural = false;
                else
                    Assert.Fail();
            }

            Assert.AreEqual(expected, actural);
        }

        [TestMethod()]
        public void RemoveAircraftTestC()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            int id = 1;
            bool expected = false;
            bool actural = true;
            target.RemoveAircraft(id);
            try
            {
                MyPoint p = target.GetPosition(id);
            }
            catch (Exception e)
            {
                if (e.Message == "The given aircraft id does not exist")
                    actural = false;
                else
                    Assert.Fail();
            }

            target.AddAircraft(id,new MyPoint(100,100),0);
            Assert.AreEqual(expected, actural);
        }


        /// <summary>
        ///A test for IfUserExist
        ///</summary>
        [TestMethod()]
        public void IfUserExistTestA()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = string.Empty; // TODO: Initialize to an appropriate value
            bool expected = false;
            bool actural = target.IfUserExist(username);
            Assert.AreEqual(expected, actural);
        }

        [TestMethod()]
        public void IfUserExistTestB()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = @"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            // This username does not exist in database, so we just call it without see if expected and actual
            // values are equal

            bool expected = false;
            bool actural = target.IfUserExist(username);
            Assert.AreEqual(expected, actural);
        }

        [TestMethod()]
        public void IfUserExistTestC()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "※€™⅛	♪";
            // This username does not exist in database, so we just call it without see if expected and actual
            // values are equal
            try
            {
                bool actural = target.IfUserExist(username);
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }

        [TestMethod()]
        public void IfUserExistTestD1()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "福尔摩斯";
            // This username does not exist in database, so we just call it without see if expected and actual
            // values are equal
            try
            {
                bool actural = target.IfUserExist(username);
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }

        [TestMethod()]
        public void IfUserExistTestD2()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "ホルムス";
            // This username does not exist in database, so we just call it without see if expected and actual
            // values are equal
            try
            {
                bool actural = target.IfUserExist(username);
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }

        [TestMethod()]
        public void IfUserExistTestE()
        {
            IGameEngineService target = CreateIGameEngineService(); // TODO: Initialize to an appropriate value
            string username = "Watson";
            // This username does not exist in database, so we just call it without see if expected and actual
            // values are equal
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual = target.IfUserExist(username);
            Assert.AreEqual(expected, actual);
        }

    }
}
